package model

import (
	"github.com/shopspring/decimal"
	"grpc_tapd_s/mysql"
	"log"
	"time"
)

type M struct {
	Id              int64
	ParentId        string
	CategoryId      int64
	Ids             int64
	Name            string
	Owner           string
	EffortCompleted string
	Last            string
	Status          string
	Creator         string
	Created         string
	CreateTime      time.Time
	Complete        time.Time
	ThisEffort      decimal.Decimal
	CustomFieldOne  string
}

func (M) TableName() string {
	return "tapd"
}
func GetAll(beginTime, endTime string) []M {
	var m []M
	result := mysql.Db.
		Where("create_time > ? and create_time <= ?", beginTime, endTime).
		Order("category_id").
		Select("id", "parent_id", "category_id", "custom_field_one", "ids", "name", "owner", "effort_completed", "status",
			"creator", "created", "create_time", "complete").
		Find(&m)
	if err := result.Error; err != nil {
		log.Printf("Db.Find err:%v\n", err)
	}
	return m
}

func GetAlla(beginTime, endTime, sta string) []M {
	var m []M
	result := mysql.Db.
		Where("complete > ? and complete <= ? and status = ?", beginTime, endTime, sta).
		Order("category_id").
		Select("id", "parent_id", "category_id", "custom_field_one", "ids", "name", "owner", "effort_completed", "status",
			"creator", "created", "create_time", "complete").
		Find(&m)
	if err := result.Error; err != nil {
		log.Printf("Db.Find err:%v\n", err)
	}
	return m
}
